# @Time    :2025/4/7 11:07
# import multiprocessing
# import os
#
#
# class Worker(multiprocessing.Process):
#     def __init__(self,name):
#         super().__init__()
#         self.name = name
#
#     def run(self):
#         # print(f"进程id:{self.pid},进程名字：{self.name},父进程id:{self}")
#         print(f"进程id:{os.getpid},进程名字：{self.name},父进程id:{os.getppid()}")
#
#
# if __name__ == "__main__":
#     for i in range(5):
#         # Worker().start()
#         p = Worker("my_p_"+str(i))
#         p.start()
#-------------------------------------------------


# import multiprocessing
# import os
#
#
# class Worker(multiprocessing.Process):
#     def __init__(self,name):
#         super().__init__()
#         self.name = name
#
#     def run(self):
#         # print(f"进程id:{self.pid},进程名字：{self.name},父进程id:{self}")
#         print(f"进程id:{os.getpid},进程名字：{self.name},父进程id:{os.getppid()}")
#
#
# if __name__ == "__main__":
#     for i in range(5):
#         # Worker().start()
#         p = Worker("my_p_"+str(i))
#         p.start()
#-----------------另一种写法-----实例方法不加实例属性，Worker().start()----------
import multiprocessing
import os


class Worker(multiprocessing.Process):
    def __init__(self):
        super().__init__()

    def run(self):
        print(f"进程id:{self.pid},进程名字：{self.name},父进程id:{os.getppid()}")
   #     print(f"进程id:{os.getpid},进程名字：{self.name},父进程id:{os.getppid()}")


if __name__ == "__main__":
    #创建进程对象
    for i in range(5):
        Worker().start()


